package org.despair2D.ui 
{
	import flash.system.ApplicationDomain;
	import org.despair2D.debug.Logger;
	import org.despair2D.ui.events.InteractiveEvent;
	import org.despair2D.ui.puppet.NineScalePuppet;
	
	import org.despair2D.core.ns_despair;
	import org.despair2D.ui.supportClasses.AbstractButton;

	use namespace ns_despair;
	
	
public class ScaleButton extends AbstractButton 
{
	
	public function ScaleButton( data:String ) 
	{
		addLeaveEffectListener(onLeave);
		addHoverEffectListener(onOver);
		addPressEffectListener(onPress);
		addDisableEffectListener(onDisable)
		this.setNineScaleData(data)
	}
	
	
	public function get bindingPuppet() : NineScalePuppet
	{
		return m_nineScalePuppet
	}
	
	
	final override public function get width() : Number
	{
		return m_nineScalePuppet.width
	}
	
	final public function set width( v:Number ) : void
	{
		m_nineScalePuppet.width = v
	}
	
	
	final override public function get height() : Number
	{
		return m_nineScalePuppet.height
	}
	
	final public function set height( v:Number ) : void
	{
		m_nineScalePuppet.height = v
	}
	
	
	
	final public function setSize( width:Number, height:Number ) : void
	{
		m_nineScalePuppet.setSize(width, height)
	}
	
	
	final public function setNineScaleData( data:String ) : void
	{
		if (!ApplicationDomain.currentDomain.hasDefinition(data + 1))
		{
			Logger.reportError(this, 'setNineScaleData', '第一帧不可为null !!')
		}
		
		m_overNineScale = ApplicationDomain.currentDomain.hasDefinition(data + 2) ? 2 : m_leaveNineScale
		m_pressNineScale = ApplicationDomain.currentDomain.hasDefinition(data + 3) ? 3 : m_overNineScale
		m_disableNineScale = ApplicationDomain.currentDomain.hasDefinition(data + 4) ? 4 : 1
		
		if(m_nineScalePuppet)
		{
			m_nineScalePuppet.setNineScale(data + m_leaveNineScale)
		}
		
		else
		{
			m_nineScalePuppet = this.createNineScalePuppet(data + m_leaveNineScale)
		}
		m_data = data
	}
	
	
	
	final ns_despair function onOver() : void
	{
		m_nineScalePuppet.setNineScale(m_data + m_overNineScale)
	}
	
	
	final ns_despair function onLeave() : void
	{
		m_nineScalePuppet.setNineScale(m_data + m_leaveNineScale)
	}
	
	
	final ns_despair function onPress() : void
	{
		m_nineScalePuppet.setNineScale(m_data + m_pressNineScale)
	}
	
	
	final ns_despair function onDisable() : void
	{
		m_nineScalePuppet.setNineScale(m_data + m_disableNineScale)
	}
	
	
	override ns_despair function recycle() : void
	{
		super.recycle();
		m_nineScalePuppet = null;
	}
	
	
	
	ns_despair var m_nineScalePuppet:NineScalePuppet
	
	ns_despair var m_data:String
	
	ns_despair var m_leaveNineScale:int = 1
	
	ns_despair var m_overNineScale:int
	
	ns_despair var m_pressNineScale:int
	
	ns_despair var m_disableNineScale:int
	
}

}